#ifndef __FileSystem_hpp__
#define __FileSystem_hpp__

#include "Pointer.hpp"
#include "Singleton.hpp"
#include "Array.hpp"
#include "InputStream.hpp"
#include "OutputStream.hpp"
#include "Logger.hpp"

namespace ge {

GE_DECLARE_CLASS( FileSystem );

//----------------------------------------------------------------------------//
// FileSystem
//----------------------------------------------------------------------------//

class FileSystem : public virtual ReferenceCounted, public Singleton< FileSystem >
{
 public:

     FileSystem( void );

     //static bool PathEquals( const String& _a, const String& _b );

     //static void AddDir( const String& _dir, float _priority = 0.0f );

     static bool IsFullPath( const String& _path );

     static String Device( const String& _path );

     static String PathTo( const String& _path );

     static String Name( const String& _path );

     static String ShortName( const String& _path );

     static String Ext( const String& _path );

     static void SplitPath( const String& _path, String* _device, StringArray* _items );

     static String MakePath( const String& _device, const StringArray& _items );

     static String MakeName( const String& _name, const String& _ext );

     static String MakeFullPath( const String& _path, const String& _base );

     static String ToFullPath( const String& _path );

     static bool FileExists( const String& _path );

     static bool DirectoryExists( const String& _path );

     static InputStreamPtr OpenFile( const String& _path, bool _throw = true );

     static InputStreamPtr OpenResource( const String& _path, bool _throw = true )
     {
          return OpenFile( ResourcePath( _path ), _throw );
     }

     static OutputStreamPtr RewriteFile( const String& _path, bool _throw = true );

     static const String& AppName( void )
     {
          return Instance().m_app_name;
     }

     static const String& AppDir( void )
     {
          return Instance().m_app_dir;
     }

     static void SetResourcesDir( const String& _dir )
     {
          Instance().m_resources_dir = ToFullPath( _dir );
     }

     static const String ResourcesDir( void )
     {
          return Instance().m_resources_dir;
     }

     static String ResourcePath( const String& _path )
     {
          return MakeFullPath( _path, ResourcesDir() );
     }

 protected:


     virtual ~FileSystem( void );

     static bool _IsObjectExists( const String& _full_path );

     static bool _IsFile( const String& _full_path );

     static bool _CreateDir( const String& _full_path );

     String m_app_name;
     String m_app_dir;
     LoggerPtr m_logger;
     String m_resources_dir;
};

} // namespace ge

#endif//__FileSystem_hpp__
